package com.ruoyi.app.controller;


import com.ruoyi.app.model.vo.LoginReq;
import com.ruoyi.app.model.vo.RegisterReq;
import com.ruoyi.app.model.vo.RegisterRes;
import com.ruoyi.app.model.vo.SendCodeReq;
import com.ruoyi.app.service.SmsService;
import com.ruoyi.app.service.UserService;
import com.ruoyi.common.annotation.PassToken;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.common.utils.JwtTokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.HashMap;
import java.util.Map;


@Api(value = "账号相关", tags = "账号相关接口")
@RestController
@RequestMapping("/api/account")
public class AccountController {


    @Autowired
    private UserService userService;

    @Autowired
    private SmsService smsService;

    @ApiOperation("登录")
    @GetMapping("/login")
    @PassToken
    public AjaxResult login(@Validated LoginReq req) {
        return AjaxResult.success(userService.login(req));
    }


    @ApiOperation("手机号注册")
    @PostMapping("/register")
    @PassToken
    public AjaxResult register(@Validated @RequestBody RegisterReq req) {
        return AjaxResult.success(userService.register(req));
    }


    @ApiOperation("发送验证码")
    @GetMapping("/send-code")
    @PassToken
    public AjaxResult sendCode(@Validated SendCodeReq req) {
        return AjaxResult.success(smsService.sendCode(req.getPhone()));
    }


    @ApiOperation("【测试使用】 根据手机号删除账号")
    @GetMapping("/del-account")
    @PassToken
    public AjaxResult delAccount(@RequestParam("account") String account) {
        return AjaxResult.success(userService.delAccount(account));
    }


}
